<template>
    <div>
        <el-form ref="form" :model="form" label-width="80px" :inline="true">
            <el-form-item label="用户名">
                <el-input v-model="form.username" @keydown.native.enter="doLogin"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="form.password"  @keydown.native.enter="doLogin"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="doLogin">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {mapActions} from 'vuex'
    import mainApi from '@/api/main'
    import session from '@/utils/session'
    import Cookies from 'js-cookie'

    export default {
        name: "login",
        data() {
            return {
                form: {
                    username: 'admin',
                    password: '123456',
                    grant_type: 'password',
                    client_secret: 'sky',
                    client_id: 'sky'
                }
            }
        },
        methods: {
            async doLogin() {
                await mainApi.doLogin(this.form).then(result => {
                    session.setToken(result);
                });

                if(session.getAccessToken()) {
                    this.$router.push("/home");
                }
            }
        }
    }
</script>

<style scoped>

</style>
